package com.sunjob.mrologdb.logConsumer;

import com.alibaba.fastjson.JSON;
import com.sunjob.common.domain.system.SysBusinessLog;
import com.sunjob.mrologdb.mapper.SysBusinessLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Wangzurong
 * @create 2022-08-02 10:35
 */
@Configuration
@Slf4j
public class BusinessLogConsumer {
    @Autowired
    SysBusinessLogMapper sysBusinessLogMapper;

    @KafkaListener(topics = "businessLog", groupId = "businessLogConsumerGourp1")
    public void businessLogConsume(SysBusinessLog sysBusinessLog) {
        log.info("{}", sysBusinessLog);
        Map sysBusinessLogMap = new HashMap();
        sysBusinessLogMap.put("businessLogId", sysBusinessLog.getBusinessLogId());
        sysBusinessLogMap.put("businessLogContent", JSON.toJSONString(sysBusinessLog.getBusinessLogContent()));
        sysBusinessLogMap.put("businessLogStatus", sysBusinessLog.getBusinessLogStatus().getValue());
        sysBusinessLogMap.put("businessLogModule", sysBusinessLog.getBusinessLogModule().getValue());
        sysBusinessLogMap.put("businessLogTime", sysBusinessLog.getBusinessLogTime());
        sysBusinessLogMap.put("businessLogCost", sysBusinessLog.getBusinessLogCost());
        sysBusinessLogMap.put("businessLogUserId", sysBusinessLog.getBusinessLogUserId());
        sysBusinessLogMapper.saveSysBusinessLog(sysBusinessLogMap);
    }
}
